<?
 require_once("../inc/functions.php");

 require_once("../inc/inventory.php");
 
 if(isset($_POST['Sku_id']))
 {
 	$results = addInventory($_POST);
	
	if($results === true)
	{
		if(isset($_SERVER['HTTP_REFERER']))
		{
			$cleaned_url = get_string_before($_SERVER['HTTP_REFERER'], "?");
			$cleaned_url .= "?id=".$_POST['Sku_id']."&inventory";
			header("location:$cleaned_url");
		}
	}
 }
 
 $products_result = getProducts();
 
?>
<!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <title><?=$title ?> Add Inventory: <?=$row['id'] ?></title>
         <? require('../inc/header-info.php'); ?>
    </head>
    <body>
        <div class="container">
            <? include('../inc/nav.php'); ?>
			<h4>Add Inventory:</h4>
				<form class="addInventory" method="post" action="<?=$url?>inventory/addinventory.php">
					<select name="Sku_id">
					<? while($product = $products_result->fetch_assoc()): ?>
    					
  						<option value="<?=$product['Sku']?>"
  							<? if(isset($_GET['id']))
  								{
  									if($_GET['id'] == $product['Sku']){ ?>selected='selected'<? } 
									
  								}?>>
							
							
  							<?=$product['name']?> <?=$product['product_name']?></option>
                    <? endwhile; ?>
                    </select>
                <input class="required" type="number" name="change_units" placeholder="Quantity">
                <button type="submit" class="btn btn-primary">Add Inventory</button>
				</form>  
		</div>
		<script type="text/javascript" src="http://jzaefferer.github.com/jquery-validation/jquery.validate.js"></script>
		<script>
			$(function() {
	
				$("form").validate();
		
			});
		</script>
	</body>
</html>

<?
/*
 */

?>